package com.tongcao.cn.validator.cons;

/**
 * @Author:tongcao
 * @Date:2019/4/26 15:33
 * Description:
 */
public enum MessageEnum {

    ENUM("ENUM_ERROR_CODE","只能为({})中的一个值"),
    DOMAIN("DOMAIN_ERROR_CODE","域名格式不正确"),
    MAX("MAX_ERROR_CODE","必须小于{1}的数字"),
    PHONE("PHONE_ERROR_CODE","电话号码格式不正确"),
    SIZE("SIZE_ERROR_CODE","长度必须大于等于{1}且小于等于{2}"),
    EMAIL("EMAIL_ERROR_CODE","邮箱格式不正确"),
    NOT_BLANK("NOT_BLANK_ERROR_CODE","不能为NULL且不能为空"),
    NOT_NULL("NOT_NULL_ERROR_CODE","不能为NULL"),
    URL("URL_ERROR_CODE","网址格式不正确"),
    MAX_LENGTH("MAX_LENGTH_ERROR_CODE","字符串长度必须小于{1}个字符"),
    NOT_EMPTY("NOT_EMPTY_ERROR_CODE","不能为空"),
    DATE("DATE_ERROR_CODE","时间格式不正确"),
    MIN_LENGTH("MIX_LENGTH_ERROR_CODE","字符串长度必须大于{1}个字符"),
    MIX("MIX_ERROR_CODE","null"),
    MOBILE("MOBILE_ERROR_CODE","手机号码格式不正确"),
    RANGE("RANGE_ERROR_CODE","必须大于等于{1}且小于等于{2}");

    private String code;
    private String value;

    MessageEnum(String code, String name) {
        this.code = code;
        this.value = name;
    }

    /**
     * 获取券名称
     *
     * @param code
     * @return
     */
    public static String getMessageValue(String code) {
        for (MessageEnum messageEnum : MessageEnum.values()) {
            if (messageEnum.getCode() == code) {
                return messageEnum.getValue();
            }
        }
        return "";
    }


    public static MessageEnum getMessageEnum(String code) {
        for (MessageEnum messageEnum : MessageEnum.values()) {
            if (messageEnum.getCode() == code) {
                return messageEnum;
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}